#!/bin/bash
# using root priviledge

reset=0

while getopts "rh" arg
do
    case $arg in
            r) reset=1
               ;;
            h) echo "Usage: $0 [option]"
               echo "Options:"
               echo "  -r reset hugepage configuration"
               echo "  -h show this message"
               exit 0
               ;;
            ?) echo "unkonw argument"
               exit 1
               ;;
    esac
done

if [ $reset -eq 0 ]
then
    sysctl -w vm.nr_hugepages=64
    mkdir -p /mnt/hugepage2M
    mount -t hugetlbfs -o pagesize=2M none /mnt/hugepage2M
else
    sysctl -w vm.nr_hugepages=0
    umount /mnt/hugepage2M
    rm -rf /mnt/hugepage2M
fi
